import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { Park } from './park';


@Injectable()
export class ParkDataProvider {
  private readonly baseUlr:string='https://api.bmob.cn/1';
  private readonly httpHeaders:HttpHeaders = new HttpHeaders({
   'X-Bmob-Application-Id':'6e6bf62b608bf75e33c70b265b071891',
   'X-Bmob-REST-API-Key':'e6b798634423f2dde8ec72c979763139',
   'Content-Type':'application/json'

  }

  );
  constructor(public http: HttpClient) {
  }

  getParks(num:number,Page:number):Observable<Park[]>{
     let _params = new HttpParams()
     .set('limit',`${num}`)
     .set('skip',`${( Page -1)*num}`);
     return this.http.get<Park[]>(`${this.baseUlr}/classes/parks`,
     {headers:this.httpHeaders,params:_params}).map(_=>_['results']);
  }

}
